<template>
  <div class="login-phone">
    <el-form :model="phone" :rules="rules" ref="formRef">
      <!-- label-width表示label的宽度 -->
      <!-- props是方便rules规则匹配的 -->
      <el-form-item label="手机号" prop="num">
        <el-input v-model="phone.num"></el-input>
      </el-form-item>
      <el-form-item label="验证码" prop="code">
        <div class="get-code">
          <el-input v-model="phone.code"></el-input>
          <el-button type="primary" class="get-btn">获取验证码</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { ElForm } from "element-plus";
import { defineComponent, reactive, ref } from "vue";
import { rules } from "../config/phone-config";
import { useStore } from "vuex";
export default defineComponent({
  setup() {
    const store = useStore();
    const phone = reactive({
      num: "",
      code: "",
    });
    const formRef = ref<InstanceType<typeof ElForm>>();
    const loginAction = () => {
      formRef.value?.validate((valid) => {
        if (valid) {
          store.dispatch("login/phoneLoginAction", { ...phone });
        }
      });
    };
    return {
      phone,
      rules,
      formRef,
      loginAction,
    };
  },
});
</script>

<style scoped lang="less">
.get-code {
  display: flex;
  .get-btn {
    margin-left: 8px;
  }
}
</style>
